package com.learn.english.controller;

import com.learn.english.domain.R;
import com.learn.english.service.IUserService;
import com.learn.english.service.ICourseService;
import com.learn.english.service.IVideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.Map;

/**
 * 首页统计数据控制器
 * 提供首页所需的各类统计信息
 */
@RestController
@RequestMapping("/admin/home")
public class HomeController {

    @Autowired
    private IUserService userService;

    @Autowired
    private ICourseService courseService;

    @Autowired
    private IVideoService videoService;

    /**
     * 获取首页统计数据
     * @return 包含用户总数、课程总数、视频总数、消息数量等统计信息的map
     */
    @GetMapping("/stats")
    public R<Map<String, Object>> getHomeStats() {
        Map<String, Object> stats = new HashMap<>();
        
        // 获取用户总数
        long userCount = userService.getUserCount();
        stats.put("userCount", userCount);
        
        // 获取课程总数
        long courseCount = courseService.getCourseCount();
        stats.put("courseCount", courseCount);
        
        // 获取视频总数
        long videoCount = videoService.getVideoCount();
        stats.put("videoCount", videoCount);
        
        // 暂时设置消息数量为固定值，后续可以根据实际情况从数据库获取
        stats.put("messageCount", 0);
        
        return R.ok(stats);
    }
}